#################################################################################
### Racialized Misinformation, Factual Corrections, and Prejudicial Attitudes ###
### [Demographic Information for Study 3]                                     ###
### Authors: Eddy S. F. Yeung, Joseph Glasgow                                 ###
### Date: June 26, 2025                                                       ###
#################################################################################

### Set-up ----
## Clean the working environment and set the working directory
rm(list = ls())
setwd("~/Desktop/racialized_misinfo/replication/Study 3") # set your working directory here, which should also contain the survey data ("study3_dataset.csv")

## Import the dataset
df <- read.csv("study3_dataset.csv")

## Load the required packages
library(tidyverse)

### Recode individual covariates ----
## Age (6 categories)
df$age <- df$yob + 12
df <- df %>% 
  mutate(
    age6 = case_when(
      age >= 18 & age <= 24 ~ 1,
      age >= 25 & age <= 34 ~ 2,
      age >= 35 & age <= 44 ~ 3,
      age >= 45 & age <= 54 ~ 4,
      age >= 55 & age <= 64 ~ 5,
      age >= 65             ~ 6
    )
  )

## Female (= 1)
df$female <- df$gender - 1

## Ethnicity (0 = White; 1 = Black; 2 = Hispanic; 3 = other)
df <- df %>% mutate(race4 = case_when(
  racial == 1 ~ 0,
  racial == 2 ~ 1,
  racial == 3 ~ 2,
  racial >= 4 ~ 3
))

## Income (4 categories)
df <- df %>% 
  mutate(
    inc4 = case_when(
      income >= 1 & income <= 7   ~ 1,
      income >= 8 & income <= 12  ~ 2,
      income >= 13 & income <= 14 ~ 3,
      income >= 15 & income <= 17 ~ 4
    )
  )

### Analyze the demographic distributions ----
## Gender
with(df, table(female)) %>% prop.table() * 100

## Age
with(df, table(age6)) %>% prop.table() * 100

## Ethnicity
with(df, table(race4)) %>% prop.table() * 100

## Income
with(df, table(inc4)) %>% prop.table() * 100
